package com.ktg.mes.pro.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ktg.common.core.domain.APIResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.core.domain.Result;
import com.ktg.mes.pro.domain.ProWaring;
import com.ktg.mes.pro.service.IProWaringService;
import com.ktg.common.utils.poi.ExcelUtil;

/**
 * 收录生产警告警告Controller
 *
 * @author byteco
 * @date 2022-11-28
 */
@RestController
@RequestMapping("/pro/proWaring")
public class ProWaringController extends BaseController
{
    @Autowired
    private IProWaringService proWaringService;

    /**
     * 查询收录生产警告警告列表
     */
    @PreAuthorize("@ss.hasPermi('pro:proWaring:list')")
    @GetMapping("/list")
    public Result<IPage<ProWaring>> list(ProWaring proWaring,
                                            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                            @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                            HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("查询收录生产警告警告列表",req,null);
        try {
            Page<ProWaring> page = new Page<ProWaring>(pageNo, pageSize);
            IPage<ProWaring> pageList = proWaringService.queryPageList(proWaring,page);
            return apiLog.ok(pageList);
        }catch (Exception e){
            return apiLog.error(e);
        }
    }

    /**
     * 导出收录生产警告警告列表
     */
    @PreAuthorize("@ss.hasPermi('pro:proWaring:export')")
    @Log(title = "收录生产警告警告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProWaring proWaring,HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("导出收录生产警告警告列表",req,proWaring);
        try {
            List<ProWaring> list = proWaringService.queryList(proWaring);
            ExcelUtil<ProWaring> util = new ExcelUtil<ProWaring>(ProWaring.class);
            util.exportExcel(response, list, "收录生产警告警告数据");
            apiLog.ok(null);
        }catch (Exception e){
            apiLog.error(e);
        }
    }

    /**
     * 获取收录生产警告警告详细信息
     */
    @PreAuthorize("@ss.hasPermi('pro:proWaring:query')")
    @GetMapping(value = "/{id}")
    public Result<ProWaring> getInfo(@PathVariable("id") Long id,HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("获取收录生产警告警告详细信息",req,null);
        try {
            return apiLog.ok(proWaringService.getInfo(id));
        }catch (Exception e){
            return apiLog.error(e);
        }
    }

    /**
     * 新增收录生产警告警告
     */
    @PreAuthorize("@ss.hasPermi('pro:proWaring:add')")
    @Log(title = "收录生产警告警告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result<String> add(@RequestBody ProWaring proWaring,HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("新增收录生产警告警告",req,proWaring);
        try {
            proWaringService.insert(proWaring);
            return apiLog.ok("添加成功！");
        }catch (Exception e){
            return apiLog.error(e);
        }
    }

    /**
     * 修改收录生产警告警告
     */
    @PreAuthorize("@ss.hasPermi('pro:proWaring:edit')")
    @Log(title = "收录生产警告警告", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public Result<String> edit(@RequestBody ProWaring proWaring,HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("修改收录生产警告警告",req,proWaring);
        try {
            proWaringService.update(proWaring);
            return apiLog.ok("编辑成功！");
        }catch (Exception e){
            return apiLog.error(e);
        }
    }

    /**
     * 删除收录生产警告警告
     */
    @PreAuthorize("@ss.hasPermi('pro:proWaring:remove')")
    @Log(title = "收录生产警告警告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result<String> remove(@PathVariable Long[] ids,HttpServletRequest req)
    {
        APIResult apiLog = new APIResult("删除收录生产警告警告",req,null);
        try {
            proWaringService.delete(ids);
            return apiLog.ok("删除成功！");
        }catch (Exception e){
            return apiLog.error(e);
        }

    }
}
